<template>
    <el-form ref="form" :model="form" label-width="80px" size="mini" label-position="left">
        <el-form-item label="积分比" v-qx="quanxian.jifen">
            <el-input v-model="form.jifenpercent" placeholder="积分获取比例（0-1）"></el-input>
        </el-form-item>
        <el-form-item label="充值比" v-qx="quanxian.chongzhi">
            <el-input v-model="form.chongzhipercent" placeholder="充值提成比例（0-1）"></el-input>
        </el-form-item>
        <el-form-item label="开卡比" v-qx="quanxian.kaika">
            <el-input v-model="form.kaikapercent" placeholder="开卡提成比例（0-1）"></el-input>
        </el-form-item>
        <el-form-item label="欠款设置">
            <el-radio-group v-model="form.isqian">
                <el-radio :label="0">不能欠款</el-radio>
                <el-radio :label="1">可以欠款</el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item>
            <!-- <el-form-item label="产品设置">
      <el-radio-group v-model="form.shopaddgoods">
        <el-radio :label="0">分店不能创建产品</el-radio>
        <el-radio :label="1">分店可以创建产品</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item> -->
            <el-button type="primary" size="mini" @click="onSubmit">保存</el-button>
            <el-button size="mini" @click="close">关闭</el-button>
        </el-form-item>
    </el-form>
</template>
<script>
import C from '#/src/common/common.js'
import Setting from '#/src/shop/setting.js'
export default {
    name: 'index',
    data() {
        return {
            form: {
                jifenpercent: '',
                chongzhipercent: '',
                kaikapercent: '',
                shopaddgoods: '',
                isqian: 0
            },
            quanxian: {
                jifen: 'richang_jifen',
                chongzhi: 'richang_chongzhi',
                kaika: 'richang_kaika',
            }
        }
    },
    methods: {
        async onSubmit() {
            if (!/^(1|0|0\.\d+)$/.test(this.form.jifenpercent)) {
                C.error('积分比设置不正确!')
                return false
            }
            if (!/^(1|0|0\.\d+)$/.test(this.form.chongzhipercent)) {
                C.error('充值比设置不正确!')
                return false
            }
            if (!/^(1|0|0\.\d+)$/.test(this.form.kaikapercent)) {
                C.error('开卡比设置不正确!')
                return false
            }
            let res = await Setting.setSetting(this.form)
            if (res) {
                C.success(res.data)
                // 更新缓存
                C.setLocalStorage('initConfig', JSON.stringify(this.form))
            }
        },
        close() {
            C.closeBrowserWindow()
        },
        async getSetting() {
            this.form = await Setting.getSetting()
        }
    },
    mounted: function() {
        this.getSetting()
    }
}
</script>
<style>
</style>